(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.lookup.acctPatternController', acctPatternController);
	acctPatternController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig', 'validatorConfig', 'authService' ];
	function acctPatternController($scope, $q, $uibModalInstance, Constants, dialogsModule, gridService, modalService, layoutConfig, validatorConfig, authService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("acctPatternLookup");
		ctrl.dialogsModule = dialogsModule;
		ctrl.config = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		
		ctrl.ok = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['ok'] || dialogsModule.btnCallback['ok']() !== false) {
				$uibModalInstance.close();
			}
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
		ctrl.init = function() {
			ctrl.gridOptions = gridService.createInnerGridOptions($scope, ctrl.config.tableConfigs.table, rowSelectionChanged);
			ctrl.gridOptions.data = 'vm.acctPattern.list';
			ctrl.gridOptions.enableRowHeaderSelection = false;
			ctrl.gridOptions.enableSelectAll = false;
			ctrl.acctPattern = {};
			ctrl.search();
		};
		
		function rowSelectionChanged(eventRow, selectedRows) {
		//	ctrl.selectedRows = selectedRows;
		}

		ctrl.search = function() {
			ctrl.acctPattern.list = [];
			authService.search().then(function(response) {
				angular.merge(ctrl.acctPattern.list, response.data);
				gridService.updateGridOptions(ctrl.acctPattern, ctrl.gridOptions);
			}, angular.noop);
		};
	}
})(angular);
